from app import db


class Room(db.Document):
    roomId = db.IntField()
    number = db.IntField()
    leaderId = db.StringField()
    temperature = db.FloatField()
    humility = db.FloatField()
    status = db.StringField()
    memo = db.StringField()
    isDoorOpened = db.BooleanField()
    isWaterBoiled = db.BooleanField()
    path = db.StringField()
    meta = {'collection': 'rooms', 'strict': False}

    @classmethod
    def get_by_room_id(cls, roomId):
        return cls.objects(roomId=roomId).first()

    @classmethod
    def get_all(cls):
        result = cls.objects()
        return result

    def json(self):
        return {
            "id": str(self.id),
            "roomId": self.roomId,
            "number": self.number,
            "leaderId": self.leaderId,
            "temperature": self.temperature,
            "humility": self.humility,
            "status": self.status,
            "memo": self.memo,
            "isDoorOpened": self.isDoorOpened,
            "isWaterBoiled": self.isWaterBoiled,
            "path": self.path
        }
